package main

import (
	"bytes"
	"flag"
	"fmt"
	"io"
	"log"

	// "token/controllers"
	"token/models"
	"token/utils/logger"
	"token/utils/path"

	"github.com/gin-gonic/gin"
)

var Poi string = "poi"

func init() {
	path.InitPath("./logs")

	gin.DefaultWriter = io.MultiWriter(logger.Logger)
	//		gin.DefaultErrorWriter = io.MultiWriter(logger.Logger)
	log.SetOutput(gin.DefaultWriter)
}

func main() {
	var mysql_user, mysql_pwd, mysql_database string
	flag.StringVar(&mysql_user, "mu", "root", "mysql user")
	flag.StringVar(&mysql_pwd, "mp", "root", "mysql password")
	flag.StringVar(&mysql_database, "md", "p2p", "mysql database")
	flag.Parse()
	models.InitDB(mysql_user, mysql_pwd, mysql_database)
	buf := bytes.NewBuffer(make([]byte, 0, 1000*100))
	buf.Reset()
	buf.WriteString("SELECT `id`,`order_sn`,`buyer_id`, IFNULL(`station_company`,''), `station_serial`,`station_gunid`,`oil_num`, ")
	buf.WriteString("`order_amount`,`pay_amount`,`trade_rposTime`,`trade_businessDate`, IFNULL(`datas`,'') FROM `")
	buf.WriteString("fuel_trade")
	buf.WriteString("` WHERE ")
	buf.WriteString("`id` > '20950730' AND `order_state`=20 ORDER BY `id` ASC LIMIT 1000")
	rows, err := models.DB.DB().Query(buf.String())
	if err != nil {
		panic(err)
	}
	var poi uint64
	var memID string
	var orderSn, company, station, gunid, rposTime, bizDate, datas string
	var quantity, amount, payAmount string
	for rows.Next() {
		err = rows.Scan(&poi, &orderSn, &memID, &company, &station, &gunid, &quantity, &amount, &payAmount, &rposTime, &bizDate, &datas)
		if err != nil {
			fmt.Println(`scan tbFuelTrade:`, err)
			break
		}

		fmt.Println(poi, orderSn, memID, company, station, gunid, quantity, amount, payAmount, rposTime, bizDate, datas)
		break
	}

	// router := gin.Default()
	// router.POST("/id", controllers.ApplyID)
	// router.POST("/update", controllers.UpdateUser)
	// router.POST("/signOut", controllers.SignOut)

	// router.Run(":8090")
}
